﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IESN.BusinessCore;
using IESN.Common;

namespace IESN.Communication
{
    public partial class CommTestFrm : Form
    {
        IPLC objcomm;
        private short strLinkType = 1;//0xe8
        public CommTestFrm()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterParent;

            if (strLinkType == 0xe8)
            {
                this.objcomm = new Comm(AppConfiguration.LinkAddr, AppConfiguration.PortNum, AppConfiguration.BaudRate, AppConfiguration.TimeOut);
            }
            else if (strLinkType == 1)
            {
                this.objcomm = new SysmacAx(AppConfiguration.EtNodeAddr, AppConfiguration.EtUnitAddr);
            } 
            
        }

        private void btnRead_Click(object sender, EventArgs e)
        {
            var aStartIndex = txtStartIndex.Text.Trim();
            var aLength = txtLength.Text.Trim();
            short aDmAddress = 0;
            short aDmCount = 0;
            short.TryParse(aLength, out aDmCount);
            var aResult = string.Empty;
            if (short.TryParse(aStartIndex, out aDmAddress) ){
                aResult = objcomm.NReadWord(aDmAddress, aDmCount);
                ltContent.Items.Add(aResult);
                ltContent.Items.Add(Environment.NewLine);
            }
        }

        private void btnWrite_Click(object sender, EventArgs e)
        {

        }
    }
}
